package com.huabo.system.oracle.mapper;

import com.hbfk.util.DateUtil;
import com.hbfk.util.PageInfo;
import com.huabo.system.oracle.entity.TblPersonalTrain;

import java.math.BigDecimal;
import java.util.List;

public class TblPersonTrainMapperSqlConfig {


    public String updateTrain(TblPersonalTrain train) {
        StringBuffer sql = new StringBuffer("UPDATE tbl_personal_train SET  trainwitness = "+train.getTrainwitness()+" ");

        if(train.getTrainevidence() != null && !"".equals(train.getTrainevidence() )) {
            sql.append(" , trainevidence = '"+train.getTrainevidence()+"'");
        }
        if(train.getTrainlocation() != null && !"".equals(train.getTrainlocation())) {
            sql.append(" , trainlocation = '"+train.getTrainlocation()+"'");
        }
        if(train.getTraintime() != null && !"".equals(train.getTraintime())) {
            sql.append(" ,CREATETIME = TO_DATE('"+ DateUtil.parseDate(train.getTraintime(),"yyyy-MM-dd HH:mm:ss") +"', 'YYYY-MM-DD HH24:MI:SS')");
        }
        sql.append(" WHERE trainid = '"+train.getTrainid()+"'");
        return sql.toString();
    }


    public String saveTrain(TblPersonalTrain ts) {
        StringBuffer column = new StringBuffer("INSERT INTO tbl_personal_train (trainid");
        StringBuffer value = new StringBuffer(" VALUES (ANALUSIS_USER_SEQUENCE.nextval");

        if(ts.getTrainwitness() != null && !"".equals(ts.getTrainwitness())) {
            column.append(",trainwitness");
            value.append(",'"+ts.getTrainwitness()+"'");
        }
        if(ts.getTrainevidence() != null && !"".equals(ts.getTrainevidence())) {
            column.append(",trainevidence");
            value.append(",'"+ts.getTrainevidence()+"'");
        }
        if(ts.getTrainlocation() != null && !"".equals(ts.getTrainlocation())) {
            column.append(",trainlocation");
            value.append(",'"+ts.getTrainlocation()+"'");
        }
        if(ts.getTraintime() != null && !"".equals(ts.getTraintime())) {
            column.append(",traintime");
            value.append(",TO_DATE('"+ DateUtil.parseDate(ts.getTraintime(),"yyyy-MM-dd HH:mm:ss") +"', 'YYYY-MM-DD HH24:MI:SS')");
        }
        if(ts.getStaffid() != null && !"".equals(ts.getStaffid())) {
            column.append(",staffid");
            value.append(",'"+ts.getStaffid()+"'");
        }
        column.append(")");
        value.append(")");
        String sql = column.toString()+value.toString();
        return sql;
    }
    
}
